import Router from 'koa-router';
import serviceContent from '../../service/content/index.js';
import serviceModel from '../../service/model/index.js';
import serviceArticle from '../../service/article/index.js';
import _ from 'lodash';
const router = new Router();
router.get('/:id', async (ctx) => {
  const { id } = ctx.params || {};
  if (_.isNil(id)) {
    ctx.body = 'not found page';
    return;
  }

  const row = await serviceArticle.getDetails(id);
  if (!row) {
    ctx.body = response.fail({ msg: 'fail' });
  } else {
    let modelId = null;
    let name = null;
    let html = '';

    const list = row.map((item) => {
      modelId = item?.modelId;
      name = item?.name;
      const value = JSON.parse(item?.value);
      if (typeof value === 'string') {
        html += value;
      }
    });
    ctx.set('Content-Type', 'text/html');

    ctx.body = `<html>
    <header>
    <meta charSet="utf-8" />
    <title>${name}</title>
    </header>
    <body>
      <h2>${html}</h2>
    </body>
    </html>`;
  }
});
export default router;
